home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / term43-source.lha / Extras / Source / gtlayout-Source.lha / LTP_GlyphSetup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  2.1 KB  |  119 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1994 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. BOOLEAN __regargs
  10. LTP_GlyphSetup(struct LayoutHandle *Handle,struct TextAttr *TextAttr)
  11. {
  12.     struct TextFont *Font;
  13.  
  14.     if(TextAttr)
  15.     {
  16.         Handle -> TextAttr = TextAttr;
  17.  
  18.         if(!(Font = OpenFont(Handle -> TextAttr)))
  19.         {
  20.             if(SysBase -> ThisTask -> tc_Node . ln_Type != NT_TASK)
  21.             {
  22.                 struct Library *DiskfontBase;
  23.  
  24.                 if(DiskfontBase = OpenLibrary("diskfont.library",0))
  25.                 {
  26.                     Font = OpenDiskFont(Handle -> TextAttr);
  27.  
  28.                     CloseLibrary(DiskfontBase);
  29.                 }
  30.             }
  31.         }
  32.  
  33.         if(Font)
  34.         {
  35.             if(Handle -> CloseFont)
  36.                 CloseFont(Handle -> RPort . Font);
  37.             else
  38.                 Handle -> CloseFont = TRUE;
  39.         }
  40.     }
  41.     else
  42.     {
  43.         Handle -> TextAttr = Handle -> Screen -> Font;
  44.  
  45.         Font = Handle -> DrawInfo -> dri_Font;
  46.  
  47.         if(Handle -> CloseFont)
  48.         {
  49.             CloseFont(Handle -> RPort . Font);
  50.  
  51.             Handle -> CloseFont = FALSE;
  52.         }
  53.     }
  54.  
  55.     if(Font)
  56.     {
  57.         LONG    Count = 0;
  58.         LONG    Total = 0;
  59.         UBYTE    Glyph;
  60.         UWORD    i;
  61.  
  62.         LTP_SetFont(Handle,Font);
  63.  
  64.             // Ok, first cover the standard ASCII character set
  65.  
  66.         for(i = 32 ; i < 127 ; i++,Count++)
  67.         {
  68.             Glyph = i;
  69.  
  70.             Total += TextLength(&Handle -> RPort,&Glyph,1);
  71.         }
  72.  
  73.             // Now for the ISO part...
  74.  
  75.         for(i = 160 ; i < 256 ; i++,Count++)
  76.         {
  77.             Glyph = i;
  78.  
  79.             Total += TextLength(&Handle -> RPort,&Glyph,1);
  80.         }
  81.  
  82.         Handle -> GlyphWidth = Total / Count;
  83.  
  84.             // Now for the numeric characters
  85.  
  86.         for(Total = 0, i = '0' ; i <= '9' ; i++)
  87.         {
  88.             Glyph = i;
  89.  
  90.             Total += TextLength(&Handle -> RPort,&Glyph,1);
  91.         }
  92.  
  93.             // Actually, the numeric character should be
  94.             // just as wide as the space character. Let's
  95.             // hope for the best.
  96.  
  97.         Total += TextLength(&Handle -> RPort," ",1);
  98.  
  99.         Total /= 11;
  100.  
  101.         if(Total > Handle -> GlyphWidth)
  102.             Handle -> GlyphWidth = Total;
  103.  
  104.         if(Handle -> GlyphWidth <= 8)
  105.             Handle -> InterWidth = 4;
  106.         else
  107.             Handle -> InterWidth = Handle -> GlyphWidth / 2;
  108.  
  109.         if(Handle -> RPort . TxHeight <= 8)
  110.             Handle -> InterHeight = 2;
  111.         else
  112.             Handle -> InterHeight = Handle -> RPort . TxHeight / 4;
  113.  
  114.         return(TRUE);
  115.     }
  116.     else
  117.         return(FALSE);
  118. }
  119.